package com.lotusfall.mapper;

import com.lotusfall.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {
    /**
     * 通过用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from tb_user where username=#{username}")
    User selectByUsername(String username);


    /**
     * 分页查询用户
     * @param page
     * @param pageSize
     * @return
     */
    @Select("select  * from tb_user limit #{page},#{pageSize}")
    List<User> queryUserList(int page, int pageSize);

    /**
     * 查找所有用户
     * @return
     */
    @Select("select * from tb_user")
    List<User> queryAll();

    /**
     * 添加用户
     * @param username
     * @param password
     * @return
     */
    @Insert("insert into tb_user values(null,#{username},#{password},#{email},#{tel},#{sex},#{avatar},#{created})")
    int addUser(User user);

    /**
     * 设置用户头像url
     * @param username
     * @param url
     * @return
     */
    @Update("update tb_user set avatar = #{url} where username = #{username}")
    int setUserAvatarUrl(@Param("username")String username, @Param("url")String url);

    @Select("select * from tb_user where id = #{id}")
    User getUserById(Long id);


    Map<Long, User> getAllUsersIdMap();
}
